//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using Tathata.Common.Caching;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;
using System.Globalization;
using Tathata.Common.DAL;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.EntityCollections;
using Tathata.Common.DAL.Managers;
using Tathata.Common.BLL.Enums;
using Tathata.Common.Utils;
using System.Web;

namespace Tathata.Common.BLL.Managers
{
    /// <summary>
    /// Log manager
    /// </summary>
    public class LogManager
    {
        #region Methods
        /// <summary>
        /// Deletes a log item
        /// </summary>
        /// <param name="LogID">Log item identifier</param>
        public static void DeleteLog(int LogID)
        {
            LogDBManager.DeleteLog(LogID);
        }

        /// <summary>
        /// Clears a log
        /// </summary>
        public static void ClearLog()
        {
            LogDBManager.ClearLog();
        }

        /// <summary>
        /// Gets all log items
        /// </summary>
        /// <returns>Log item collection</returns>
        public static LogCollection GetAllLogs()
        {
            return LogDBManager.GetAllLogs();
        }

        /// <summary>
        /// Gets a log item
        /// </summary>
        /// <param name="LogID">Log item identifier</param>
        /// <returns>Log item</returns>
        public static Log GetByLogID(int LogID)
        {
            return LogDBManager.GetByLogID(LogID);
        }

        /// <summary>
        /// Inserts a log item
        /// </summary>
        /// <param name="LogType">Log item type</param>
        /// <param name="Message">The short message</param>
        /// <param name="Exception">The full exception</param>
        /// <returns>A log item</returns>
        public static Log InsertLog(LogTypeEnum LogType, string Message,
            string Exception)
        {
            int CustomerID = 0;
            if (NopContext.Current.User != null)
                CustomerID = NopContext.Current.User.CustomerID;
            string IPAddress = HttpContext.Current.Request.UserHostAddress;
            string PageURL = CommonHelper.GetThisPageName();

            return InsertLog(LogType, 11, Message,
             Exception, IPAddress, CustomerID, PageURL);
        }

        /// <summary>
        /// Inserts a log item
        /// </summary>
        /// <param name="LogType">Log item type</param>
        /// <param name="Severity">The severity</param>
        /// <param name="Message">The short message</param>
        /// <param name="Exception">The full exception</param>
        /// <param name="IPAddress">The IP address</param>
        /// <param name="CustomerID">The customer identifier</param>
        /// <param name="PageURL">The page URL</param>
        /// <returns>Log item</returns>
        public static Log InsertLog(LogTypeEnum LogType, int Severity, string Message,
            string Exception, string IPAddress, int CustomerID, string PageURL)
        {
            if (IPAddress == null)
                IPAddress = string.Empty;
            return LogDBManager.InsertLog((int)LogType, Severity, Message,
             Exception, IPAddress, CustomerID, PageURL, DateTime.Now);
        }
        #endregion
    }
}
